# pip install dashscope
from http import HTTPStatus
import dashscope


def get_answer(api_key, question):
    answer = '│ AL：'
    messages = [{"role": "system",
                "content": "在选项中找出问题的正确答案，请保证信息的准确，并在回答时保持简洁，只回答对应的选项就行，不需要任何其他分析反馈。"},
                {"role": "user", "content": question}]
    try:
        response = dashscope.Generation.call(
            model="qwen-turbo",
            messages=messages,
            api_key=api_key,
            result_format='message',  # 将返回结果格式设置为 message
        )
        if response.status_code == HTTPStatus.OK:
            answer += response["output"]["choices"][0]["message"]["content"]
            print(answer)
        else:
            print('Request id: %s, Status code: %s, error code: %s, error message: %s' % (
                response.request_id, response.status_code,
                response.code, response.message
            ))
    except Exception as e:
        print('[报错]' + str(e))

# api_key = 'sk-aaf301da8eab4ae7883c080e2b621341'
# get_answer(api_key, '《本草纲目》的演唱者是谁？ 李时珍 王安石 苏轼 周杰伦')
